<template>
  <div class="app-container home">
    <el-row>
      <el-col :span="24" :offset="1">
        表名：<el-select v-model="value" filterable  placeholder="请选择"
      @change="getFieldInfo"
      >
        <el-option
          v-for="item in options"
          :key="item"
          :label="item"
          :value="item">
          <!-- {{item}} -->
        </el-option>
        </el-select>
      </el-col>
      <el-col :span="24" :offset="1">
        <p>表说明：{{tableData.tableComment}}</p>
        <p>数据条数：{{tableData.tableRows}}</p>
        <p>数据长度：{{tableData.dataLength}} 兆</p>
        <p>索引占的内存：{{tableData.indexLength}} 兆</p>
      </el-col >
      <el-col :span="24" :offset="1">
        <el-table
        :data="tableData.dbFieldVos"
        stripe
        style="width: 70%">
          <el-table-column
            type="index"
            label="序号"
            width="180">
          </el-table-column>
          <el-table-column
            prop="columnName"
            label="字段名"
            width="180">
          </el-table-column>
          <el-table-column
            prop="columnType"
            label="字段类型"
            width="180">
          </el-table-column>
          <el-table-column
            prop="columnComment"
            label="字段说明"
            width="380">
          </el-table-column>
          <el-table-column
            label="操作">
            <template slot-scope="scope">
              <!-- <el-button icon="el-icon-edit" circle></el-button> -->
              <!-- <el-button type="text" size="small">查看</el-button> -->
              <!-- <el-button @click="handleClick(scope.row)" type="text" size="small">编辑</el-button> -->
              <el-button @click="handleClick(scope.row)" type="primary" icon="el-icon-edit" size="mini">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <el-dialog
      title="字段说明修改"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
      <el-form :model="fieldInfo" class="demo-form-inline">
        <el-form-item label="字段名称">
          <el-input disabled v-model="fieldInfo.columnName" placeholder="字段名称"></el-input>
        </el-form-item>
        <el-form-item label="字段类型" prop="pass">
          <el-input disabled v-model="fieldInfo.columnType" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="字段说明" prop="pass">
          <el-input v-model="fieldInfo.columnComment" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleEdit">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import { getTableName } from "@/api/monitor/database";
import { getFieldInfo } from "@/api/monitor/database";
import { updateFieldInfo } from "@/api/monitor/database";

export default {
  name: "Index",
  data() {
    return {
      // 版本号
      // version: "3.6.0",
      options:[],
      value:'',
      tableData:{
        dataLength:0,
        indexLength:0
      },
      // 修改dialog是否展示
      dialogVisible:false,
      // 选中的字段数据
      fieldInfo:{
        tableName: '',
        columnName:'',
        columnType:'',
        columnComment:''
      }
    };
  },
  created() {
    this.getDataTable()
    console.log('created');
  },
  methods: {
    // 获取表名
    getDataTable() {
      getTableName().then(res => {
        this.options = res
        console.log(this.options);
      });
    },
    getFieldInfo(value) {
      getFieldInfo(value).then(res => {
        this.tableData = res
        this.fieldInfo.tableName = value
        console.log(this.tableData);
      })
    },
    // 点击编辑按钮
    handleClick(row) {
      this.dialogVisible = true
      this.fieldInfo = row
      console.log(this.fieldInfo);
    },
    // 关闭对话框之前的回调
    handleClose() {},
    // 点击确定
    handleEdit() {
      this.dialogVisible = false;
      console.log(this.fieldInfo);
      // updateFieldInfo(this.fieldInfo).then(res => {

      // })

    }
  },
};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  .el-col {
    // border-radius: 4px;
    margin-top: 20px;
    margin-bottom: 30px;
    border-top: 1px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

